package com.xiaolong.log.config;

import com.xiaolong.log.send.RocketMqSendHandler;
import com.xiaolong.log.send.SendHandler;
import com.xiaolong.log.util.SendUtil;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Configuration
@ConditionalOnProperty(prefix = "buding.log", name = "type", havingValue = "ROCKET", matchIfMissing = false)
@ConditionalOnBean(RocketMQTemplate.class)
@AutoConfiguration
@Order(1)
public class RocketMqSendLogConfiguration {

    @Bean
    public SendHandler rocketMqSendHandler(LogProperties logProperties, RocketMQTemplate rocketMQTemplate) {
        RocketMqSendHandler rocketMqSendHandler = new RocketMqSendHandler(rocketMQTemplate, logProperties);
        SendUtil.init(rocketMqSendHandler);
        return rocketMqSendHandler;
    }
}